package com.obas.access.business.service.impl;

import java.util.ArrayList;
import java.util.List;

import com.ease.platform.access.service.impl.AbstractNamespaceAccessServiceImpl;
import com.obas.access.business.service.TestPlanAccessService;
import com.obas.access.business.service.TestTaskAccessService;
import com.obas.access.business.service.TestTaskItemAccessService;
import com.obas.business.common.vo.TestTaskResult;
import com.obas.model.business.TestPlan;
import com.obas.model.business.TestTask;

public class TestPlanAccessServiceImpl extends AbstractNamespaceAccessServiceImpl<TestPlan> implements TestPlanAccessService {

    private TestTaskAccessService testTaskAccessService;

    private TestTaskItemAccessService testTaskItemAccessService;

    @Override
    public List<TestTaskResult> getTestResultById(long id) {
        List<TestTask> testtasks = testTaskAccessService.findByTestPlanId(id);
        if (testtasks == null || testtasks.size() == 0) {
            return new ArrayList<TestTaskResult>();
        }
        List<TestTaskResult> results = new ArrayList<TestTaskResult>(testtasks.size());
        for (TestTask task : testtasks) {
            TestTaskResult result = new TestTaskResult();
            result.setTask(task);
            result.setTestTaskItems(testTaskItemAccessService.findByTestTaskId(task.getId()));
            results.add(result);
        }
        return results;
    }

    public void setTestTaskAccessService(TestTaskAccessService testTaskAccessService) {
        this.testTaskAccessService = testTaskAccessService;
    }

    public void setTestTaskItemAccessService(
            TestTaskItemAccessService testTaskItemAccessService) {
        this.testTaskItemAccessService = testTaskItemAccessService;
    }

}
